package com.chb.weibo3;


import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.KeyValueTextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class LastRunJob {
	public static void main(String[] args) throws Exception {
		System.setProperty("HADOOP_USER_NAME", "chb");
		Configuration conf = new Configuration();
		FileSystem fs = FileSystem.get(conf);
		
		Job job = Job.getInstance();
		job.setJar("C:\\Users\\12285\\Desktop\\weibo3.jar");
		job.setJarByClass(LastRunJob.class);
		job.setJobName("LastRunJob");
		
		job.setMapperClass(LastMapper.class);
		job.setReducerClass(LastReducer.class);
		
		job.setMapOutputKeyClass(Text.class);
		job.setMapOutputValueClass(Text.class);
		job.setInputFormatClass(KeyValueTextInputFormat.class);
		
		
		//将小表加载到内存中，微博总数
		job.addCacheFile(new Path("hdfs://TEST:9000/user/chb/output/outweibo1/part-r-00003").toUri());
		//df
		job.addCacheFile(new Path("hdfs://TEST:9000/user/chb/output/outweibo2/part-r-00000").toUri());
		
		FileInputFormat.addInputPath(job, new Path("hdfs://TEST:9000/user/chb/output/outweibo1/"));
		Path out = new Path("hdfs://TEST:9000/user/chb/output/outweibo3/");
		if (fs.exists(out)) {
			fs.delete(out, true);
		}
		FileOutputFormat.setOutputPath(job, out);
		
		boolean f = job.waitForCompletion(true);
		if (f) {
			System.out.println("最后一个mapreduce执行完成");
			
		}
	}
}
